package com.smart.speaker.websocket.tool;

import com.alibaba.dashscope.tools.FunctionDefinition;
import com.alibaba.dashscope.tools.ToolFunction;
import com.google.gson.JsonObject;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component(value = "get_current_date")
public class GetDateTool implements Tool {

    private final ToolFunction function;

    public GetDateTool() {
        JsonObject parameters = new JsonObject();
        parameters.addProperty("type", "object");
        function = ToolFunction.builder().function(FunctionDefinition.builder().name("get_current_date")
                .description("获取当前时刻的日期")
                .parameters(parameters).build()).build();
    }

    @Override
    public ToolResp call(String params) {
        LocalDate now = LocalDate.now();
        int month = now.getMonthValue();
        int day = now.getDayOfMonth();
        String content = "今天是" + month + "月" + day + "日";
        return new ToolResp(Type.RESPONSE, content);
    }

    @Override
    public ToolFunction getFunction() {
        return function;
    }

}
